package com.user.controller;

import com.user.pojo.User;
import com.user.service.impl.UserServiceImpl;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

@RestController
@RefreshScope
public class UserController {

    @Autowired
    private UserServiceImpl userService;

    @RequestMapping(value = "/register", method = RequestMethod.POST)
    public void register(@RequestBody User user) throws Exception {
        userService.register(user);
    }

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public void login(@RequestBody User user) throws Exception {
        boolean login = userService.login(user);
        if (login){
            System.out.println("登录成功");
        }else {
            System.out.println("登录失败");
        }
    }

    @RequestMapping(value = "/findByName", method = RequestMethod.POST)
    public String findByName(@RequestParam("username") String username) throws Exception {
        User user = userService.findByName(username);
        return user.toString();
    }

    @Value("${user.name}")
    private String name;


    @RequestMapping(value = "refresh", method = RequestMethod.GET)
    public String refresh(){
        return name;
    }

}
